import {
  Controller,
  Post,
  Body,
  UseGuards,
  Request,
  Get,
  Delete,
  Put,
  Param,
  Query,
} from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { CreateCooperateDto } from './dto/create-cooperate.dto';
import { CooperateService } from './cooperate.service';
import { Cooperate } from './cooperate.entity';
import { RemoveCooperateDto } from './dto/remove-cooperate.dto';
import { RetrieveCooperateDto } from './dto/retrieve-cooperate.dto';
import { UpdateCooperateDto } from './dto/update-cooperate.dto';
import { FindCooperateDto } from './dto/find-cooperate.dto';
import { JwtAuthGuardUser } from 'src/auth/guards/jwt-auth.guard';

@ApiTags('合作')
@Controller('api/cooperate')
export class CooperateController {
  constructor(private readonly cooperateService: CooperateService) {}

  // 增加
  // @UseGuards(JwtAuthGuardUser)
  @Post()
  @ApiOperation({ summary: '增加' })
  async create(
    @Body() createCooperateDto: CreateCooperateDto,
  ): Promise<Cooperate> {
    return await this.cooperateService.create(createCooperateDto);
  }

  // 删除
  @UseGuards(JwtAuthGuardUser)
  @Delete()
  @ApiOperation({ summary: '删除' })
  async remove(@Body() removeCooperateDto: RemoveCooperateDto): Promise<any> {
    return await this.cooperateService.delete(removeCooperateDto);
  }

  // 更新
  @UseGuards(JwtAuthGuardUser)
  @Put(':id')
  @ApiOperation({ summary: '更新' })
  async update(
    @Param() params: RetrieveCooperateDto,
    @Body() updateCooperateDto: UpdateCooperateDto,
  ): Promise<any> {
    return await this.cooperateService.update({
      id: params.id,
      updateCooperateDto,
    });
  }

  // 列表
  // @UseGuards(JwtAuthGuard)
  @Get()
  @ApiOperation({ summary: '列表' })
  async findAll(@Query() query: FindCooperateDto): Promise<Cooperate> {
    return await this.cooperateService.findAll(query);
  }

  // 根据 id 查找
  @Get(':id')
  @ApiOperation({ summary: '根据 id 查找' })
  async findOneById(@Param() params: RetrieveCooperateDto): Promise<any> {
    return await this.cooperateService.findOneById(params.id);
  }

  // 数量
  @Get('list/count')
  @ApiOperation({ summary: '用户数量' })
  async getCount(@Query() query: FindCooperateDto) {
    return await this.cooperateService.getCount(query);
  }
}
